package com.jbit.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jbit.dto.DmItem;
import com.jbit.mapper.DmItemMapper;
import com.jbit.service.DmItemService;
import com.jbit.vo.DmItemVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 节目表(DmItem)表服务实现类
 *
 * @author makejava
 * @since 2023-07-22 10:50:19
 */
@Service("dmItemService")
public class DmItemServiceImpl implements DmItemService {
    @Resource
    private DmItemMapper dmItemMapper;


    @Override
    public List<DmItem> queryItemByTypeId(Integer typeId) {
        return dmItemMapper.queryItemByTypeId(typeId);
    }

    @Override
    public List<DmItem> queryBanner() {
        return dmItemMapper.queryBanner();
    }

    @Override
    public List<DmItem> queryFloorItemByTypeId(Integer typeId) {
        return dmItemMapper.queryFloorItemByTypeId(typeId);
    }

    @Override
    public PageInfo queryItemList(DmItemVo dmItemVo) {
        PageHelper.startPage(dmItemVo.getCurrentPage(), 10);
        PageInfo pageInfo = new PageInfo(dmItemMapper.queryItemList(dmItemVo));
        return pageInfo;
    }

    @Override
    public List<DmItem> queryAllFloor(Integer id) {
        return dmItemMapper.queryAllFloor(id);
    }

    @Override
    public List<DmItem> queryToSaleItem() {
        return dmItemMapper.queryToSaleItem();
    }

    @Override
    public List<DmItem> queryItemLike(Map<String,Object> map) {
        return dmItemMapper.queryItemLike(map);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public DmItem queryById(Integer id) {
        return this.dmItemMapper.queryById(id);
    }


    /**
     * 新增数据
     *
     * @param dmItem 实例对象
     * @return 实例对象
     */
    @Override
    public DmItem insert(DmItem dmItem) {
        this.dmItemMapper.insert(dmItem);
        return dmItem;
    }

    /**
     * 修改数据
     *
     * @param dmItem 实例对象
     * @return 实例对象
     */
    @Override
    public DmItem update(DmItem dmItem) {
        this.dmItemMapper.update(dmItem);
        return this.queryById(dmItem.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.dmItemMapper.deleteById(id) > 0;
    }
}
